package com.acme.bankapp.mail;

import java.util.LinkedList;

public class Queue {
	private LinkedList<EMail> queue = new LinkedList<EMail>();

	public void add(EMail email) {
		synchronized (queue) {
			queue.add(email);
			queue.notifyAll();
		}
	}

	public EMail get() {
		synchronized (this.queue) {
			EMail email = null;
			while (queue.isEmpty()) {
				try {
					queue.wait();
				} catch (InterruptedException e) {
					return email;
				}
			}
			email = queue.removeLast();
			return email;
		}
	}
}
